﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Yitter.IdGenerator;
using static S.EliminationOrDath.API.Application.Command.EOrDCommand.EliminationReadCommand;

namespace S.EliminationOrDath.Read.API.Controllers
{
    /// <summary>
    /// 控制器读--淘汰
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class EliminationReadController : ControllerBase
    {
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数，用于依赖注入
        /// </summary>
        /// <param name="mediator">中介者实例</param>
        public EliminationReadController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 获取全部信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetAlls()
        {
            return Ok(await mediator.Send(new GetEliminationAllCommand()));
        }
        /// <summary>
        /// 显示类型
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetTypes()
        {
            return Ok(await mediator.Send(new GetTypesCommand()));
        }
        /// <summary>
        /// 显示品种
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetVarietyEnums()
        {
            return Ok(await mediator.Send(new GetVarietyEnumsCommand()));
        }
        /// <summary>
        /// 显示淘汰
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetPhaseOutReason()
        {
            return Ok(await mediator.Send(new GetPhaseOutReasonCommand()));
        }
        /// <summary>
        /// 显示处理措施
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetTreatmentMeasure()
        {
            return Ok(await mediator.Send(new GetTreatmentMeasureCommand()));
        }
        /// <summary>
        /// 雪花Id显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetYitIdHelper()
        {
            return Ok(YitIdHelper.NextId());
        }
        /// <summary>
        /// 淘汰管理列表
        /// </summary>
        /// <param name="StartDate"></param>
        /// <param name="EndDate"></param>
        /// <param name="EarTag"></param>
        /// <param name="OutReason"></param>
        /// <param name="LeaveOrNot"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Eliminationmanagement(DateTime? StartDate,DateTime? EndDate,string? EarTag,int OutReason,bool? LeaveOrNot,int pageIndex,int pageSize)
        {
            return Ok(await mediator.Send(new EliminationmanagementCommand() { StartDate = StartDate, EndDate = EndDate, EarTag = EarTag, OutReason = OutReason, LeaveOrNot = LeaveOrNot, pageIndex = pageIndex, pageSize = pageSize }));
        }
        /// <summary>
        /// 通过Id查询淘汰信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> EliminationmanagementId(int Id)
        {
            return Ok(await mediator.Send(new EliminationmanagementIdCommand() { Id = Id}));
        }
        /// <summary>
        /// 根据耳号查询淘汰信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> EliminationmanagementEarTag(string? ear)
        {
            return Ok(await mediator.Send(new EliminationmanagementEarTagCommand() { EarTag = ear}));
        }
        /// <summary>
        /// 根据耳号查询档案信息
        /// </summary>
        /// <param name="er"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetArchives(string er)
        {
            return Ok(await mediator.Send(new GetArchivesCommand() {EarTag = er }));
        }
    }
}
